package com.erclab.xbuilder.formelements;

import com.erclab.internal.xpresso.formelements.Hidden;
import com.erclab.internal.xpresso.forms.Form;
import com.erclab.xbuilder.exception.XBuilderException;
import com.erclab.xbuilder.managers.MysqlFormManager;

public class DestinationColumnCreator extends Hidden {

	@Override
	public String[] processSubmittedValues(Form theForm, String[] submittedValues) {
		String dColumn = "";
		try {
			if (theForm.getFormParameters().getAction().equalsIgnoreCase("insert")){
				dColumn = new MysqlFormManager().getNumberOfFields(theForm.getFormParameters().getUniqueKeyValue()) + "";
			} else {
				dColumn = new MysqlFormManager().getNumberOfFields(theForm.getFormParameters().getParentKeyValue()) + "";
			}
			dColumn = "col_" + dColumn;
			this.userValue = dColumn;
		} catch (XBuilderException e){
			// TODO: Log this and throw an error
		}
			
		return new String[]{dColumn};
	}
	
}
